function [xcf,auto,yxcf]=multicross2var(y,x,t)
%%
[n,N]=size(y);
xcf=zeros(2*t+1,N);
offset=1e-6;
%%
yf=fft(bsxfun(@rdivide,bsxfun(@minus,full(y),mean(y)),full(std(y)+offset)));
xf=fft(full((x(:)-mean(x))./(std(x)+offset)));
%%
for i=1:N
    tmp=ifft(yf(:,i).*conj(xf));
    tmp=tmp([end-t+1:end,1:t+1])/n;
    xcf(:,i)=tmp;
    xcf(:,i)=tmp(end:-1:1);
end

if nargout>1
    auto=zeros(2*t+1,N);
    yi=ifft(yf.*conj(yf));
    auto=yi(1:2*t+1,:)/n;
end

if nargout>2
    yxcf=zeros(4*t+1,N,N);
    for i=1:N
        for j=1:N
            tmp=ifft(yf(:,j).*conj(yf(:,i)));
            tmp=tmp([end-2*t+1:end,1:2*t+1])/n;
            yxcf(:,i,j)=tmp;
            yxcf(:,i,j)=tmp(end:-1:1);
        end
    end
    
end